package install.ren.exercise.test.thread.pool;

import java.util.concurrent.TimeUnit;

/**
 * @author jonny
 * Created on 2021/3/3
 */
public class PoolTeacher {
    private static Object olock = new Object();
    public static void main(String[] args) {
        // ExecutorService fixedThreadPool = Executors.newFixedThreadPool(10);
        new Thread(() -> {
            while (true){
                synchronized (olock) {
                    try {
                        // TimeUnit.SECONDS.sleep(1);
                        System.out.println(System.currentTimeMillis() + "=======1-start");
                        olock.wait(1);
                        System.out.println(System.currentTimeMillis() + "=======1-end");

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
        }
        }).start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
                try {
                    System.out.println("=======2");
                    TimeUnit.SECONDS.sleep(3);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    synchronized (olock) {
                        olock.notifyAll();
                    }
                }
        }).start();

        try {
            TimeUnit.SECONDS.sleep(30);
        } catch (InterruptedException e) {
            e.printStackTrace();

        }
    }
}
